package jxl;

import java.io.File;

import jxl.write.Label;
import jxl.write.Number;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

public class CreateXLS {
	public static void main(String[] args) {
		try {
			WritableWorkbook xls = Workbook
					.createWorkbook(new File("C:\\a.xls"));
			WritableSheet sheet = xls.createSheet("测试", 0);
			// ****************************************************
			// sheet.mergeCells(0, 0, 4, 4); // 合并单元格
			sheet.setRowView(0, 600);// 设置行高
			// 将第一列的宽度设为30
			sheet.setColumnView(0, 30);
			Label label = new Label(0, 0, "test");
			WritableFont wf = new WritableFont(WritableFont.TIMES, 12,
					WritableFont.BOLD, false);// 设置写入字体
			WritableCellFormat wcfF = new WritableCellFormat(wf);// 设置CellFormat
			Label labelCF = new Label(0, 0, "hello");// 创建写入位置,内容和格式
			sheet.addCell(label);
			Number number = new Number(1, 0, 789.123);
			sheet.addCell(number);
			xls.write();
			xls.close();
			// ********************************************
			WritableSheet sheet2 = xls.getSheet(1);// xls.createSheet("测试2", 1);
			sheet2.setRowView(0, 600);// 设置行高
			// 将第一列的宽度设为30
			sheet2.setColumnView(0, 30);
			Label label2 = new Label(0, 0, "test2");
			WritableFont wf2 = new WritableFont(WritableFont.TIMES, 12,
					WritableFont.BOLD, false);// 设置写入字体
			WritableCellFormat wcfF2 = new WritableCellFormat(wf);// 设置CellFormat
			Label labelCF2 = new Label(0, 0, "hello");// 创建写入位置,内容和格式
			sheet2.addCell(label2);
			Number number2 = new Number(1, 0, 99999);
			sheet2.addCell(number2);
			xls.write();
			xls.close();
			// *****************************************************
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
